<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
    <title>CLUSTER FORGET 命令文档翻译 - 天地维杰网</title>
    <meta name="keywords" content="系统架构,shutdown,不与天斗,Domino,博客,程序员,架构师,笔记,技术,分享,java,Redis">
    
    <meta property="og:title" content="CLUSTER FORGET 命令文档翻译">
    <meta property="og:site_name" content="天地维杰网">
    <meta property="og:image" content="/img/author.jpg"> 
    <meta name="title" content="CLUSTER FORGET 命令文档翻译 - 天地维杰网" />
    <meta name="description" content="`CLUSTER FORGET node-id`该命令用于在redis集群节点接收到该命令后从集群已知的节点集合中移除掉给定节点id的节点。换句话说，接收到命令的节点的节点表中会移除掉指定节点。" />
     
    <link rel="shortcut icon" href="http://www.shutdown.cn/img/favicon.ico" />
    <link rel="apple-touch-icon" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link rel="apple-touch-icon-precomposed" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link href="http://www.shutdown.cn/js/vendor/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/main.css" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/syntax.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
     fancybox: true, 
    motion: true
  };
</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7826003325059020" crossorigin="anonymous"></script>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<div class="container one-collumn sidebar-position-left page-home  ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-meta  custom-logo ">

  <div class="custom-logo-site-title">
    <a href="http://www.shutdown.cn"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">天地维杰网</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">人如秋鸿来有信，事若春梦了无痕</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
    <ul id="menu" class="menu">
      
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/redis/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-full"></i> <br />Redis
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/java/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-coffee"></i> <br />java
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/linux/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-linux"></i> <br />linux
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/daily/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bug"></i> <br />日常问题
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/spring/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-child"></i> <br />Spring和Springboot
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/mac/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-fire"></i> <br />Mac相关
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/middleware/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-gavel"></i> <br />中间件
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jiagou/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-rocket"></i> <br />架构
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/python/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-ship"></i> <br />python
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/front/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bolt"></i> <br />前端
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jvm/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-balance-scale"></i> <br />jvm
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/c/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-empty"></i> <br />c语言
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/web3/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-web3"></i> <br />web3
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/post/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/about/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于
          </a>
        </li>
      
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger"> <i class="menu-item-icon fa fa-search fa-fw"></i> <br /> 搜索</a>
      </li>
    </ul>
    <div class="site-search">
      <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>

    </div>
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
<section id="posts" class="posts-expand">
  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/redis-cluster-forget-node-id/" itemprop="url">
        CLUSTER FORGET 命令文档翻译
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="2022-04-02">
    2022-04-02
</time>
</span> 
      

  <span class="post-category" >
  &nbsp; | &nbsp;
  <span class="post-meta-item-icon">
    <i class="fa fa-folder-o"></i>
  </span>
  <span class="post-meta-item-text">分类：</span>
  
    <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
      <a href="http://www.shutdown.cn/categories/redis" itemprop="url" rel="index">
        <span itemprop="name">redis</span>
      </a>
      &nbsp; 
    </span>
  
</span>


      
 <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">翻译</span>
</span>

       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">1336 字 ~3分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    
    <div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback"> 翻译文章，原文地址：https://redis.io/commands/cluster-forget/</code></pre></div>
    

    

<p><strong>Available since 3.0.0.</strong></p>

<p><strong>Time complexity:</strong> O(1)</p>

<blockquote>
<p><strong>3.0.0版本后可用</strong></p>

<p><strong>时间复杂度：O(1)</strong></p>
</blockquote>

<p>The command is used in order to remove a node, specified via its node ID, from the set of <em>known nodes</em> of the Redis Cluster node receiving the command. In other words the specified node is removed from the <em>nodes table</em> of the node receiving the command.</p>

<blockquote>
<p>该命令用于在redis集群节点接收到该命令后从集群已知的节点集合中移除掉给定节点id的节点。换句话说，接收到命令的节点的节点表中会移除掉指定节点。</p>
</blockquote>

<p>Because when a given node is part of the cluster, all the other nodes participating in the cluster knows about it, in order for a node to be completely removed from a cluster, the <a href="https://redis.io/commands/cluster-forget">CLUSTER FORGET</a> command must be sent to all the remaining nodes, regardless of the fact they are masters or replicas.</p>

<blockquote>
<p>因为指定节点是集群的一部分，集群中的所有其他节点都能感知到它，为了从集群里完全移除一个节点，<code>CLUSTER FORGET</code> 命令必须发送到所有其他主节点和从节点。</p>
</blockquote>

<p>However the command cannot simply drop the node from the internal node table of the node receiving the command, it also implements a ban-list, not allowing the same node to be added again as a side effect of processing the <em>gossip section</em> of the heartbeat packets received from other nodes.</p>

<blockquote>
<p>但是，该命令不仅仅是简单地从接收命令的节点的内部节点表中删除节点，它还实现了一个禁用列表，禁止将相同节点意外加入到从其他节点接收的心跳信息包中。</p>
</blockquote>

<h2 id="details-on-why-the-ban-list-is-needed">Details on why the ban-list is needed</h2>

<h2 id="为啥需要禁用列表">为啥需要禁用列表</h2>

<p>In the following example we&rsquo;ll show why the command must not just remove a given node from the nodes table, but also prevent it for being re-inserted again for some time.</p>

<blockquote>
<p>在以下案例中，我们会展示为什么这个命令不能仅从节点列表中移除指定节点，还需要防止这个节点有时被重新插入。</p>
</blockquote>

<p>Let&rsquo;s assume we have four nodes, A, B, C and D. In order to end with just a three nodes cluster A, B, C we may follow these steps:</p>

<blockquote>
<p>我们假设我们有4个节点，A,B,C,D。为了使集群最终仅剩A,B,C节点，我们需要执行以下几步：</p>
</blockquote>

<ol>
<li>Reshard all the hash slots from D to nodes A, B, C.</li>
<li>D is now empty, but still listed in the nodes table of A, B and C.</li>
<li>We contact A, and send <code>CLUSTER FORGET D</code>.</li>
<li>B sends node A a heartbeat packet, where node D is listed.</li>
<li>A does no longer known node D (see step 3), so it starts an handshake with D.</li>
<li>D ends re-added in the nodes table of A.</li>
</ol>

<blockquote>
<ol>
<li>将D节点的槽位全部迁移到A,B,C节点</li>
<li>D节点成为空节点了，但是仍然在A,B,C的节点列表中。</li>
<li>我们联系A节点，然后发送<code>CLUSTER FORGET D</code> 命令</li>
<li>B想节点A发送心跳包，节点D的信息还在心跳包信息在</li>
<li>A节点没有D节点信息了，所以开始与D进行握手。</li>
<li>D节点重新加入了A节点的信息表中</li>
</ol>
</blockquote>

<p>As you can see in this way removing a node is fragile, we need to send <a href="https://redis.io/commands/cluster-forget">CLUSTER FORGET</a> commands to all the nodes ASAP hoping there are no gossip sections processing in the meantime. Because of this problem the command implements a ban-list with an expire time for each entry.</p>

<blockquote>
<p>可以看到，这种移出节点的方式很脆，我们需要尽快发送 <code>CLUSTER FORGET</code> 命令到所有节点，并希望在相同时间没有进行gossip交互在进行中。因为这个问题，这个命令实现了一个 禁用列表，列表中的实体都有一个超时时间。</p>
</blockquote>

<p>So what the command really does is:</p>

<blockquote>
<p>所以命令真正步骤是：</p>
</blockquote>

<ol>
<li>The specified node gets removed from the nodes table.</li>
<li>The node ID of the removed node gets added to the ban-list, for 1 minute.</li>
<li>The node will skip all the node IDs listed in the ban-list when processing gossip sections received in heartbeat packets from other nodes.</li>
</ol>

<blockquote>
<ol>
<li>指定节点从节点表中移出</li>
<li>移除的节点ID被加到了禁用列表中，持续一分钟</li>
<li>节点在处理接收到其他节点的心跳包的gossip信息时，会跳过禁用列表中所有的的节点id。</li>
</ol>
</blockquote>

<p>This way we have a 60 second window to inform all the nodes in the cluster that we want to remove a node.</p>

<blockquote>
<p>这样，我们就有了60秒的时间窗口来通知集群中的所有节点 我们想移除一个节点这个事情。</p>
</blockquote>

<h2 id="special-conditions-not-allowing-the-command-execution">Special conditions not allowing the command execution</h2>

<blockquote>
<p>不允许命令执行的特定条件</p>
</blockquote>

<p>The command does not succeed and returns an error in the following cases:
&gt; 以下情况，命令不回成功，并且会返回错误：</p>

<ol>
<li>The specified node ID is not found in the nodes table.</li>
<li>The node receiving the command is a replica, and the specified node ID identifies its current master.</li>
<li>The node ID identifies the same node we are sending the command to.</li>
</ol>

<blockquote>
<ol>
<li>指定的节点id在节点表中没有。</li>
<li>接收命令的节点是一个副本节点，并且指定的节点ID是它的当前的主节点。</li>
<li>要移除的节点ID和我们发送命令的目的节点是同一个。</li>
</ol>
</blockquote>

<h2 id="return-value">Return value</h2>

<blockquote>
<p>返回值</p>
</blockquote>

<p><a href="https://redis.io/topics/protocol#simple-string-reply">Simple string reply</a>: <code>OK</code> if the command was executed successfully, otherwise an error is returned.</p>

<blockquote>
<p>返回字符串：成功返回<code>OK</code>，否则返回错误。</p>
</blockquote>

    </div>
    <footer class="post-footer">
     
 
<div class="post-tags">     
     
    <a href="http://www.shutdown.cn/tags/redis" rel="tag" title="redis">#redis#</a>
    
    <a href="http://www.shutdown.cn/tags/cluster" rel="tag" title="cluster">#cluster#</a>
    
    <a href="http://www.shutdown.cn/tags/forget" rel="tag" title="forget">#forget#</a>
    
    <a href="http://www.shutdown.cn/tags/node" rel="tag" title="node">#node#</a>
    
</div>



     <div class="post-nav">
    <div class="post-nav-next post-nav-item">
    
        <a href="http://www.shutdown.cn/post/redis-cluster-bumpepoch/" rel="next" title="CLUSTER BUMPEPOCH">
        <i class="fa fa-chevron-left"></i> CLUSTER BUMPEPOCH
        </a>
    
    </div>

    <div class="post-nav-prev post-nav-item">
    
        <a href="http://www.shutdown.cn/post/etcd-large-scale-service-governance/" rel="prev" title="基于etcd实现大规模服务治理应用实战">
        基于etcd实现大规模服务治理应用实战 <i class="fa fa-chevron-right"></i>
        </a>
    
    </div>
</div>
      
     
     
     






    </footer>
  </article>
</section>

          </div>
        </div>
        <div class="sidebar-toggle">
  <div class="sidebar-toggle-line-wrap">
    <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
  </div>
</div>
<aside id="sidebar" class="sidebar">
  <div class="sidebar-inner">

  <ul class="sidebar-nav motion-element">
    <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
      文章目录
    </li>
    <li class="sidebar-nav-overview" data-target="site-overview">
      站点概览
    </li>
  </ul>

    <section class="site-overview sidebar-panel ">
      <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
        src="http://www.shutdown.cn/img/author.jpg"
        alt="不与天斗Domino" />
    <p class="site-author-name" itemprop="name">不与天斗Domino</p>
    <p class="site-description motion-element" itemprop="description"> 
        Programmer &amp; Architect</p>
</div>
      <nav class="site-state motion-element">
    <div class="site-state-item site-state-posts">
      <a href="http://www.shutdown.cn/post/">
        <span class="site-state-item-count">183</span>
        <span class="site-state-item-name">日志</span>
      </a>
    </div>
    <div class="site-state-item site-state-categories">    
        <a href="http://www.shutdown.cn/categories/">      
         
        <span class="site-state-item-count">15</span>
        
        <span class="site-state-item-name">分类</span>
        
        </a>
    </div>

    <div class="site-state-item site-state-tags">
        <a href="http://www.shutdown.cn/tags/">
         
        <span class="site-state-item-count">224</span>
        
        <span class="site-state-item-name">标签</span>
        </a>
    </div>
</nav>
      
      

      

      <div class="links-of-blogroll motion-element inline">
<script type="text/javascript" src="//rf.revolvermaps.com/0/0/8.js?i=&amp;m=0&amp;s=220&amp;c=ff0000&amp;cr1=ffffff&amp;f=arial&amp;l=33&amp;bv=35" async="async"></script>
</div>

    </section>
    
<section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
    <div class="post-toc">
        <div class="post-toc-content"><nav id="TableOfContents">
<ul>
<li>
<ul>
<li><a href="#details-on-why-the-ban-list-is-needed">Details on why the ban-list is needed</a></li>
<li><a href="#为啥需要禁用列表">为啥需要禁用列表</a></li>
<li><a href="#special-conditions-not-allowing-the-command-execution">Special conditions not allowing the command execution</a></li>
<li><a href="#return-value">Return value</a></li>
</ul></li>
</ul>
</nav></div>
    </div>
</section>

  </div>
</aside>

      </div>
    </main>
   
    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  <span itemprop="copyrightYear">  &copy; 
  2013 - 2023</span>
  <span class="with-love"><i class="fa fa-heart"></i></span>
  <span class="author" itemprop="copyrightHolder">天地维杰网</span>
  <span class="icp" itemprop="copyrightHolder"><a href="https://beian.miit.gov.cn/" target="_blank">京ICP备13019191号-1</a></span>
</div>
<div class="powered-by">
  Powered by - <a class="theme-link" href="http://gohugo.io" target="_blank" title="hugo" >Hugo v0.63.2</a>
</div>
<div class="theme-info">
  Theme by - <a class="theme-link" href="https://github.com/xtfly/hugo-theme-next" target="_blank"> NexT
  </a>
</div>


      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
      <span id="scrollpercent"><span>0</span>%</span>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery/index.js?v=2.1.3"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/fastclick/lib/fastclick.min.js?v=1.0.6"></script> 
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.min.js?v=1.2.1"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.ui.min.js?v=1.2.1"></script>
<script src="http://www.shutdown.cn/js/vendor/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>

<script src="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.pack.js?v=2.1.5"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/utils.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/motion.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/affix.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/schemes/pisces.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/scrollspy.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/post-details.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/toc.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/bootstrap.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX", "output/HTML-CSS"],
    tex2jax: {
      inlineMath: [ ['$','$'] ],
      displayMath: [ ['$$','$$'] ],
      processEscapes: true
    },
    "HTML-CSS": { fonts: ["TeX"] }
  });
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML' async></script>
</body>
</html>